import request from "@/utils/request";
import {downloadFileByData} from "@/utils/download";

export function getList(data) {
  return request({
    #if(data.subModuleName != null && data.subModuleName != "")
    url: "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/findPage",
    #else
    url: "#(apiPath)/#(data.moduleName)/findPage",
    #end
    method: "get",
    params: data,
  });
}


export function doInsert(data) {
  return request({
    #if(data.subModuleName != null && data.subModuleName != "")
    url: "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/insert",
    #else
    url: "#(apiPath)/#(data.moduleName)/insert",
    #end
    method: "post",
    data,
  });
}

export function doUpdate(data) {
  return request({
    #if(data.subModuleName != null && data.subModuleName != "")
    url: "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/update",
    #else
    url: "#(apiPath)/#(data.moduleName)/update",
    #end
    method: "post",
    data,
  });
}

export function doDelete(data) {
  return request({
    #if(data.subModuleName != null && data.subModuleName != "")
    url: "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/del",
    #else
    url: "#(apiPath)/#(data.moduleName)/del",
    #end
    method: "post",
    params: data,
  });
}

export function doDeleteAll(data) {
  return request({
    #if(data.subModuleName != null && data.subModuleName != "")
    url: "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/delAll",
    #else
    url: "#(apiPath)/#(data.moduleName)/delAll",
    #end
    method: "post",
    params: data,
  });
}


/**
* 导出Excel 目前只支持一层参数传递
* @param data
* @returns file
*/
export function doExportExcel(data) {
  #if(data.subModuleName != null && data.subModuleName != "")
  let requestURL = "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/exportExcel";
  #else
  let requestURL = "#(apiPath)/#(data.moduleName)/exportExcel";
  #end
  // 下载文件
  downloadFileByData(requestURL, data);
}


/**
* 下载模版
* @returns file
*/
export function doDownloadTemplate() {
  let data = {};
  #if(data.subModuleName != null && data.subModuleName != "")
  let requestURL = "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/importExcel/template";
  #else
  let requestURL = "#(apiPath)/#(data.moduleName)/importExcel/template";
  #end
  // 下载文件
  downloadFileByData(requestURL, data);
}

/**
* 导入Excel
* @returns file
*/
export function doImportExcel(data) {
  return request({
    #if(data.subModuleName != null && data.subModuleName != "")
    url: "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/importExcel",
    #else
    url: "#(apiPath)/#(data.moduleName)/importExcel",
    #end
    method: "post",
    // 最长超时时间 50秒
    timeout: 50000,
    headers: {
    'Content-Type': 'multipart/form-data'
    },
    data,
  });
}


